package Launcher;

import Modelos.TblPerfilesUsuarios;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collection;

public final class dlgSelectorPerfil extends javax.swing.JDialog {

    private Collection<TblPerfilesUsuarios> perfiles = new ArrayList<TblPerfilesUsuarios>();
    private GoBox frame;
    public dlgSelectorPerfil(java.awt.Frame parent, boolean modal, Collection<TblPerfilesUsuarios> perfiles, GoBox frame) {
        super(parent, modal);
        String usuario = "";
        for (TblPerfilesUsuarios perfil : perfiles) {
            if ((perfil.getEstatus() && perfil.getIdperfil().getEstatus())) {
                this.perfiles.add(perfil);
                usuario = perfil.getIdusuario().getNombreCorto();
                frame.setUsuarioGlobal(perfil.getIdusuario());
            }
        }
        initComponents();
        this.setLocationRelativeTo(null);
        this.frame=frame;
        if (!usuario.equals("")) {
            this.lblBienvenida.setText("Bienvenido | " + usuario);
        } else {
            this.lblBienvenida.setText("Usuario sin Perfiles Activos");
            this.lblMensaje.setText("");
        }
        tblPerfilesUser.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent me) {
                super.mouseClicked(me);
                AceptarPerfil();
            }
        });
    }

    public void AceptarPerfil() {
        int row = tblPerfilesUser.getSelectedRow();
        int i = 0;
        if (row > -1) {
            for (TblPerfilesUsuarios perfil : perfiles) {
                if (i == row) {
                    this.frame.ActivarFX(perfil.getIdperfil().getTblPantallasPerfilesCollection());
                    setVisible(false);
                }
                i++;
            }
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        jPanel1 = new javax.swing.JPanel();
        pnlRedondo1 = new org.edisoncor.gui.panel.PanelNice();
        lblMensaje = new javax.swing.JLabel();
        panelImage1 = new org.edisoncor.gui.panel.PanelImage();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblPerfilesUser = new Componentes.tblDatos();
        lblBienvenida = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Selección de Perfil");
        setResizable(false);
        setUndecorated(true);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        pnlRedondo1.setBackground(new java.awt.Color(121, 137, 167));

        lblMensaje.setBackground(new java.awt.Color(255, 255, 255));
        lblMensaje.setFont(new java.awt.Font("Lucida Grande", 1, 18)); // NOI18N
        lblMensaje.setForeground(new java.awt.Color(255, 255, 255));
        lblMensaje.setText("Seleccione el Perfil con el que desea acceder al sistema.");

        panelImage1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recursos/Imagenes/gobox_mini.png"))); // NOI18N
        panelImage1.setMinimumSize(new java.awt.Dimension(64, 64));

        org.jdesktop.layout.GroupLayout panelImage1Layout = new org.jdesktop.layout.GroupLayout(panelImage1);
        panelImage1.setLayout(panelImage1Layout);
        panelImage1Layout.setHorizontalGroup(
            panelImage1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 64, Short.MAX_VALUE)
        );
        panelImage1Layout.setVerticalGroup(
            panelImage1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 64, Short.MAX_VALUE)
        );

        tblPerfilesUser.setFont(new java.awt.Font("Lucida Grande", 0, 24)); // NOI18N
        tblPerfilesUser.setGridColor(new java.awt.Color(121, 137, 167));
        tblPerfilesUser.setOpaque(false);
        tblPerfilesUser.setRowHeight(40);
        tblPerfilesUser.setShowHorizontalLines(false);
        tblPerfilesUser.setShowVerticalLines(false);

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${perfiles}");
        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, eLProperty, tblPerfilesUser);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idperfil.nombre} : ${idperfil.descripcion}"));
        columnBinding.setColumnName("");
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane1.setViewportView(tblPerfilesUser);

        lblBienvenida.setBackground(new java.awt.Color(255, 255, 255));
        lblBienvenida.setFont(new java.awt.Font("Lucida Grande", 1, 36)); // NOI18N
        lblBienvenida.setForeground(new java.awt.Color(255, 255, 255));
        lblBienvenida.setText("Bienvenido:");

        org.jdesktop.layout.GroupLayout pnlRedondo1Layout = new org.jdesktop.layout.GroupLayout(pnlRedondo1);
        pnlRedondo1.setLayout(pnlRedondo1Layout);
        pnlRedondo1Layout.setHorizontalGroup(
            pnlRedondo1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(pnlRedondo1Layout.createSequentialGroup()
                .add(8, 8, 8)
                .add(pnlRedondo1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(pnlRedondo1Layout.createSequentialGroup()
                        .add(lblMensaje, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 662, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(panelImage1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jScrollPane1))
                .add(8, 8, 8))
            .add(pnlRedondo1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(pnlRedondo1Layout.createSequentialGroup()
                    .add(8, 8, 8)
                    .add(lblBienvenida, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 658, Short.MAX_VALUE)
                    .add(8, 8, 8)))
        );
        pnlRedondo1Layout.setVerticalGroup(
            pnlRedondo1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(pnlRedondo1Layout.createSequentialGroup()
                .addContainerGap(39, Short.MAX_VALUE)
                .add(pnlRedondo1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, lblMensaje, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 30, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, panelImage1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 371, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(16, 16, 16))
            .add(pnlRedondo1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(pnlRedondo1Layout.createSequentialGroup()
                    .add(27, 27, 27)
                    .add(lblBienvenida, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 30, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(439, Short.MAX_VALUE)))
        );

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(8, 8, 8)
                .add(pnlRedondo1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(8, 8, 8))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(8, 8, 8)
                .add(pnlRedondo1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(8, 8, 8))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                dlgSelectorPerfil dialog = new dlgSelectorPerfil(new javax.swing.JFrame(), true, null, null);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblBienvenida;
    private javax.swing.JLabel lblMensaje;
    private org.edisoncor.gui.panel.PanelImage panelImage1;
    private org.edisoncor.gui.panel.PanelNice pnlRedondo1;
    private Componentes.tblDatos tblPerfilesUser;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    public Collection<TblPerfilesUsuarios> getPerfiles() {
        return perfiles;
    }

    public void setPerfiles(Collection<TblPerfilesUsuarios> perfiles) {
        this.perfiles = perfiles;
    }
}
